package tk.hoopy.zedtown.graphics;

import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;

import tk.hoopy.zedtown.levels.Chunk;

@SuppressWarnings("serial")
public class GameWindow extends JPanel {
	
	private int winWidth, winHeight, positionX, positionY;
	private ArrayList<Chunk> drawList = new ArrayList<Chunk>();
	
	public GameWindow(String name, int width, int height) {
		this.setFocusable(true);
		
		winWidth = width*150;winHeight = height*150;
		JFrame frame = new JFrame("Zed Town");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(this);
		frame.setSize(winWidth, winHeight+27);
		frame.setResizable(false);
		frame.setVisible(true);
		positionX = 0;
		positionY = 0;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponents(g);
		for(int x=0;x<drawList.size();x++) {
			for(int y=0;y<3;y++) {
				for(int z=0;z<3;z++) {
					g.drawImage(
							drawList.get(x).GetTiles()[y][z].GetTexture(),
							(drawList.get(x).GetPositionX() + y)*50 - positionX,
							(drawList.get(x).GetPositionY() + z)*50 - positionY,
							null);
				}
			}
		}
		drawList.clear();
	}
	
	public void AddChunk(Chunk c) {
		drawList.add(c);
	}
	
	public int GetPositionX() {
		return positionX;
	}
	
	public int GetPositionY() {
		return positionY;
	}
	
	public void SetPositionX(int x) {
		positionX = x;
	}
	
	public void SetPositionY(int y) {
		positionY = y;
	}
	
	public int GetRadius() {
		return winWidth;
	}
	
	public void Refresh() {
		repaint();
	}
		
}
